package com.tech.zhidengxian.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tech.zhidengxian.model.dataobject.SchoolDO;
import com.tech.zhidengxian.model.dataobject.UserDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<UserDO> {
    LambdaQueryWrapper<UserDO> wrapper = new LambdaQueryWrapper<>();
    default List<UserDO> queryUserList(){
        return selectList(wrapper);
    }
    default int updateUserById(UserDO userDO){
        return updateById(userDO);
    }
    default UserDO pwdLogin(UserDO userDO){
        LambdaQueryWrapper<UserDO> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(UserDO.class,e->!e.getColumn().equals("password"))
                .or(wr->{
                    wr.eq(UserDO::getEmail,userDO.getUsername())
                      .or()
                      .eq(UserDO::getPhone,userDO.getUsername());
                })
                .eq(UserDO::getPassword,userDO.getPassword());

        return selectOne(wrapper);
    }
    default int register(UserDO userDO){
        return insert(userDO);
    }



}
